package Message;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import java.util.logging.SimpleFormatter;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 石方旭
 * Date: 2022-10-18
 * Time: 16:48
 */
@WebServlet("/autoRefreshServlet")
public class AutoRefreshServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //每1s自动刷新
        resp.setHeader("refresh","1");

        //获取当前时间戳
        long timeStamp = System.currentTimeMillis();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss" ,Locale.getDefault());
        Date date = new Date(timeStamp);//将时间戳转化成当前时间
        String time = simpleDateFormat.format(date);//转化成日期
        resp.getWriter().write(time);
    }
}
